package solution._0070._0077;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chen_snow
 * Date: 2021/6/21 22:56
 * Description: 组合
 */
public class Solution {
    public static void main(String[] args) {
        combine(4, 2);
    }

    public static ArrayList<List<Integer>> result = new ArrayList<>();

    public static List<List<Integer>> combine(int n, int k) {

        backTrace(new ArrayList<>(), 1, n, k);
        return result;
    }

    public static void backTrace(ArrayList<Integer> path, int start, int n, int k) {
        if (path.size() == k) {
            result.add(new ArrayList<>(path));
            return;
        }

        for (int i = start; i <= n; i++) {
            path.add(i);
            backTrace(path, i+1, n, k);
            path.remove(path.size() - 1);
        }
    }
}
